package org.apache.ibatis.ztest.interceptor;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Properties;

/**
 * @author wangxinyuchuan
 * @date 2023/5/22 9:32 PM
 */
@Intercepts(value = {
  @Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})
})
public class MyInterceptor2 implements Interceptor {

  private String name;

  private Integer age;

  @Override
  public Object intercept(Invocation invocation) throws Throwable {
    System.out.println(name);
    System.out.println(age);
    return invocation.proceed();
  }

  @Override
  public void setProperties(Properties properties) {
    name = properties.getProperty("name");
    age = Integer.valueOf(properties.getProperty("age"));
  }
}
